package com.interview.ujiuye1;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.UUID;

public class ArrayListNotSafeDemo {
    public static void main(String[] args) {
        //List<String> list = new ArrayList<>();
        List<String> list = Collections.synchronizedList(new ArrayList<>()) ;
        for (int i = 0; i < 30; i++) {
            new Thread(
                    () -> {
                        list.add(UUID.randomUUID().toString());
                        System.out.println(list);
                    },String.valueOf("线程"+i)
            ).start();
        }

    }

    private static void test1() {
        List<String> list = new ArrayList<>();
        list.add("a");
        list.add("b");
        list.add("c");

        for(String element : list) {
            System.out.println(element);
        }
    }
}